package service.impl;

import dao.IPerformanceBaseDataDao;
import dao.IPerformanceDao;
import model.Performance;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.PerformanceService;
import util.UUIDGenerator;

import java.util.List;

/**
 * Created by lvdouStart on 2017/7/12.
 */
@Service
public class PerformanceServiceImpl implements PerformanceService {

    private static Log logger = LogFactory.getLog(PerformanceServiceImpl.class);

    @Autowired
    private IPerformanceDao performanceDao;

    @Autowired
    private IPerformanceBaseDataDao performanceBaseDataDao;

    /**
     * @Author: 杨青桦
     * @Description:  控江收入填写
     * @Date: 2017/10/13 10:46
     * @param hospitalId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setPerformance(String hospitalId) {
        List<Performance> list  = performanceDao.queryPerformanceList(hospitalId);
        for(Performance performance : list){
            StringBuffer sb = new StringBuffer();
            performance.setId(UUIDGenerator.getUniqueLong());
            performance.setType(0);
            performance.setAmount(performance.getAmount()*100);
            performance.setTime(sb.append(performance.getTimeYear())
                    .append("-").append(performance.getTimeMonth()).append("-1").toString());
            performanceDao.insert(performance);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        performanceBaseDataDao.updateIsAnalyze(null);
    }

    /**
     * @Author: 杨青桦
     * @Description:  仁和绩效分析
     * @Date: 2017/10/13 10:46
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setPerformanceWithoutHis() {
        List<Performance> list  = performanceDao.queryDirectPerformance();
        for(Performance performance : list){
            performance.setId(UUIDGenerator.getUniqueLong());
            if(performance.getAmount() == null){
                performance.setAmount(0.0);
            }
            performance.setAmount(performance.getAmount()*100);
            performance.setType(0);
            performanceDao.insert(performance);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
